$(function() {
	$.post(frame.fullUrl("/base/acount/allparent.json"), function(data) {
		if (data.acounts) {
			$("#dg").datagrid("loadData", data.acounts);
		}
	});
});

var selected = -1;
function clickAcount(index, row) {
	if (selected != index) {
		selected = index;
		loadAcountInitStatus();
	}
}

function loadAcountInitStatus() {
	var row = $("#dg").datagrid("getSelected");
	if (row == null) {
		return;
	}
	$.ajax("./getacount.json", {
		data : row,
		mask : true,
		type : 'post',
		success : function(tradeAcount) {
			if (tradeAcount) {
				$("#ff").form("load", tradeAcount);
				var initPos = $.parseJSON(tradeAcount.initPos);
				$("#dg2").datagrid("loadData", initPos);
			} else {
				$("#ff").form("clear");
				$("#dg2").datagrid("loadData", {
					rows : []
				});
			}
			$("#ff").form("load", {
				acountId : row.acountId
			});
		}
	});
}

function secNameFomatter(value, row, index) {
	return frame.flex.getName("SMDC_SECURITY_SEL", row.secId)
}

function click_save() {
	var row = $("#dg").datagrid("getSelected");
	if (row == null) {
		alert("请选择账户");
		return;
	}

	var a = $("#ff").form('validate');
	if (!a) {
		return;
	}
	$("#dg2").edatagrid("saveRow");
	var posList = $("#dg2").datagrid("getData");
	posList = posList.rows;
	$('#ff').form('ajaxSubmit', {
		url : "./saveacount.json",
		data : {
			acountId : row.acountId,
			initPos : JSON.stringify(posList)
		}
	});
}

function click_ex_test(){
	var row = $("#dg").datagrid("getSelected");
	if (row == null) {
		alert("请选择账户");
		return;
	}
	$.ajax("./extest.json", {
		data : row,
		mask : true
	});
	
}

